def __save_key_value_file__(dicts: dict, f):
    for key in dicts.keys():
        value = dicts.get(key)
        line = f"{key}={value}\n"
        f.write(line)
    pass


class SharedPreferences:
    def __init__(self, filename):
        self.filename = filename

    def get_float(self, key: str, def_value):
        key_value = {}
        try:
            with open(self.filename, 'r+') as f:
                all_line = f.readlines()
                for line in all_line:
                    if line is not None:
                        result = line.strip().split("=")
                        if len(result) == 2:
                            key_value[result[0]] = float(result[1])
                print(key_value)
        except Exception:
            print("配置文件不存在")
            return def_value
        if len(key_value) == 0:
            return def_value
        value = key_value[key]

        if value is None:
            return def_value
        else:
            return value

    class Edit:
        def __init__(self, file_name: str):
            self.file = open(file_name, 'w+')
            self.all_key_value = {}
            pass

        def put(self, key: str, value):
            all_line = self.file.readlines()

            for line in all_line:
                if line is not None:
                    result = line.strip().split("=")
                    if len(result) == 2:
                        self.all_key_value[result[0]] = result[1]
            self.all_key_value[key] = value

        def commit(self):
            __save_key_value_file__(self.all_key_value, self.file)
            self.file.close()
